{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization: Polylines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## [Run this notebook on binder](https://mybinder.org/v2/gh/daavoo/pyntcloud/master)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "In this notebook we are going to learn about the different available options for visualizing polylines along with our PyntClouds."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Imports"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "from pyntcloud import PyntCloud"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Create random point cloud"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We are going to create a point cloud with random points and random colors."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "positions = np.random.rand(1000, 3) * 10\n",
    "positions -= positions.mean(0)\n",
    "\n",
    "points = pd.DataFrame(positions.astype(np.float32), columns=[\"x\", \"y\", \"z\"])\n",
    "\n",
    "points[\"red\"] = (np.random.rand(1000) * 255).astype(np.uint8)\n",
    "points[\"green\"] = (np.random.rand(1000) * 255).astype(np.uint8)\n",
    "points[\"blue\"] = (np.random.rand(1000) * 255).astype(np.uint8)\n",
    "\n",
    "cloud = PyntCloud(points)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Visualization: Polylines"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We are going to create 3 lines to represent the 3D coordinate axis."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The sintaxis to define lines is as follows:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "lines = [\n",
    "    {\"color\": \"red\", \"vertices\": [[0, 0, 0], [10, 0, 0]]},\n",
    "    {\"color\": \"green\", \"vertices\": [[0, 0, 0], [0, 10, 0]]},\n",
    "    {\"color\": \"blue\", \"vertices\": [[0, 0, 0], [0, 0, 10]]},\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cloud.plot(polylines=lines)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![polylines](data/images/visualization-Polylines-1.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Arbitrary number of vertices"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can define polylines with an arbitrary number of vertices:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "polylines = [\n",
    "    {\"color\": \"pink\", \"vertices\": [[0, 0, 0], [7, 0, 0], [10, 0, 10], [12, -2, 10]]},\n",
    "    {\"color\": \"pink\", \"vertices\": [[0, 0, 0], [0, 7, 0], [0, 10, 10]]},\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cloud.plot(polylines=polylines)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![arbitrary-vertices](data/images/visualization-Polylines-2.png)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Using hexadecimal colors"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We can also use hexadecimal notation for defining the color of our polylines:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "polylines = [\n",
    "    {\"color\": \"#00FFFF\", \"vertices\": [[0, 0, 0], [7, 0, 0], [10, 0, 10], [12, -2, 10]]},\n",
    "    {\"color\": \"#ff00ff\", \"vertices\": [[0, 0, 0], [0, 7, 0], [0, 10, 10]]},\n",
    "]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "cloud.plot(polylines=polylines)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "![hexadecimal-colors](data/images/visualization-Polylines-3.png)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
